package cn.zwb.zwb.test.ex.handle;

import cn.zwb.zwb.test.ex.ServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
//异常处理类
@RestControllerAdvice
public class GlobalExceptionHandler {

    //自定义异常
    @ExceptionHandler
    public String handleServiceException(ServiceException e) {
        return e.getMessage();
    }

    @ExceptionHandler
    public String handleNullPointerException(NullPointerException e) {
        return "程序出现了空指针异常，已经被处理！";
    }

    @ExceptionHandler
    public String handleRuntimeException(RuntimeException e) {
        return "程序出现了RuntimeException，已经被处理！";
    }
}
